<%-- 
    Document   : newEvent
    Created on : May 12, 2011, 9:24:02 PM
    Author     : enriquer
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<script type="text/javascript">
    dojo.require("dijit.layout.ContentPane");
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.MenuBar");
    dojo.require("dijit.Menu");
    dojo.require("dijit.MenuBarItem");
    dojo.require("dijit.MenuItem");
    dojo.require("dijit.form.Button");
    dojo.require("dijit.form.Form");
    dojo.require("dijit.form.ValidationTextBox");
    dojo.require("dijit.form.SimpleTextarea");
    dojo.require("dijit.form.DateTextBox");
    dojo.require("dijit.form.CheckBox");
    dojo.require("dijit.TitlePane");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("dijit.form.TimeTextBox");
    dojo.require("dijit.form.NumberSpinner");
    dojo.require("dojo.data.ItemFileReadStore");

    function onSubmit(data){
        
        if(data.success=="1"){
            setMessage("OKKK");
            dojo.byId("frmEvent").reset();
        }else{
            setMessage("Error ", true);
        }
    }

    function saveEvent(status){
        setMessage("");
        var form=dijit.byId("frmEvent");
        if(status!=null){
            dojo.byId("txtStatus").value=status;
        }
        if(form.status!=''){
            if(!dijit.byId("txtName").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtName").invalidMessage;
                dojo.byId("txtName").focus();
                return;
            }
            if(dijit.byId("txtDescription").value==''){
                dojo.byId("divMessage").innerHTML="falta";
                dojo.byId("txtDescription").focus();
                return;
            }
            if(!dijit.byId("txtStartDate").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtStartDate").invalidMessage;
                dojo.byId("txtStartDate").focus();
                return;
            }
            if(!dijit.byId("txtStartTime").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtStartTime").invalidMessage;
                dojo.byId("txtStartTime").focus();
                return;
            }
            if(!dijit.byId("txtEndDate").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtEndDate").invalidMessage;
                dojo.byId("txtEndDate").focus();
                return;
            }
            if(!dijit.byId("txtEndTime").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtEndTime").invalidMessage;
                dojo.byId("txtEndTime").focus();
                return;
            }
            if(!dijit.byId("txtLimit").isValid()){
                dojo.byId("divMessage").innerHTML=dijit.byId("txtLimit").invalidMessage;
                dojo.byId("txtLimit").focus();
                return;
            }
            //Faltan validaciones
            post("frmEvent","json");
        }
        
    }

    dojo.addOnLoad(function() {
                
        loadMenu();
        
       
    });
</script>
<div id="divBody" dojoType="dijit.layout.ContentPane" style="width: 600px; height: 550px;">
    <div id="divMessage" align="center"></div>
    <form dojoType="dijit.form.Form" id="frmEvent" name="frmEvent" action="saveEvent.htm" method="POST">
        <input type="hidden" id="txtStatus" name="txtStatus"/>
        <table cellspacing="10" align="left">
            <tr>
                <td>
                    <label for="txtName"><spring:message code="newevent.name"/></label>
                </td>
                <td>
                    <input type="text" id="txtName" name="txtName" dojoType="dijit.form.ValidationTextBox"
                           required="true" trim="true" maxLength="30" regExp="[A-Za-z0-9\s]+" widgetsInTemplate="true"
                           invalidMessage="<spring:message code="message.invalid"/>"
                           missingMessage="<spring:message code="message.empty"/>"/>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="txtDescription"><spring:message code="newevent.description"/></label>
                </td>
                <td>
                    <textarea id="txtDescription" name="txtDescription" dojoType="dijit.form.SimpleTextarea" 
                              trim="true" maxLength="50" rows="4" cols="50" style="width:auto;">
                    </textarea>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="txtStartDate"><spring:message code="newevent.startdate"/></label>
                </td>
                <td>
                    <input type="text" id="txtStartDate" name="txtStartDate" required="true" dojoType="dijit.form.DateTextBox"
                           value="${params.date}"
                           invalidMessage="<spring:message code="message.invalid"/>"
                           missingMessage="<spring:message code="message.empty"/>"/>
                    &nbsp;&nbsp;&nbsp;
                    <input type="text" id="txtStartTime" name="txtStartTime" required="true" dojoType="dijit.form.TimeTextBox"
                           displayedValue="${params.time}"
                           invalidMessage="<spring:message code="message.invalid"/>"
                           missingMessage="<spring:message code="message.empty"/>"/>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="txtEndDate"><spring:message code="newevent.enddate"/></label>
                </td>
                <td>
                    <input type="text" id="txtEndDate" name="txtEndDate" required="true" dojoType="dijit.form.DateTextBox"
                           value="${params.date}"
                           invalidMessage="<spring:message code="message.invalid"/>"
                           missingMessage="<spring:message code="message.empty"/>"/>
                    &nbsp;&nbsp;&nbsp;
                    <input type="text" id="txtEndTime" name="txtEndTime" required="true" dojoType="dijit.form.TimeTextBox"
                           displayedValue="${params.time}"
                           invalidMessage="<spring:message code="message.invalid"/>"
                           missingMessage="<spring:message code="message.empty"/>"/>
                </td>
            </tr>
            <tr>
                <td>
                    <label for="cbxPrivacy"><spring:message code="newevent.privacy"/></label>
                </td>
                <td>
                    <input id="cbxPrivacy" name="cbxPrivacy" dojoType="dijit.form.CheckBox" value="1">
                </td>
            </tr>
            <tr>
                <td>
                    <label for="txtLimit"><spring:message code="newevent.limit"/></label>
                </td>
                <td>
                    <input id="txtLimit" name="txtLimit" dojoType="dijit.form.NumberSpinner" 
                           smallDelta="1" constraints="{min:1,places:0}" 
                           invalidMessage="<spring:message code="message.invalid"/>"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <br>
                    <button dojoType="dijit.form.Button" type="button" id="btnDraft" name="btnDraft" 
                            onClick="saveEvent('0');">
                        <spring:message code="newevent.save"/>
                    </button>
                    &nbsp;&nbsp;&nbsp;
                    <button dojoType="dijit.form.Button" type="button" id="btnPublish" name="btnPublish"
                            onClick="saveEvent('1');">
                        <spring:message code="newevent.publish"/>
                    </button>
                </td>
            </tr>
        </table>
    </form>

</div>


